package com.douqu.game.core.e;

import com.douqu.game.core.config.AttributeConfig;

import java.io.Serializable;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-11-08 10:23
 */
public enum E_Attribute implements BaseEnum, Serializable {

    ATK(0, "atk"),
    ATK_GROW(0, "atkGrow"),
    DEF(0, "def"),
    DEF_GROW(0, "defGrow"),
    HP(0, "hp"),
    HP_GROW(0, "hpGrow"),
    CRI(Integer.MIN_VALUE, "cri"),
    REC(Integer.MIN_VALUE, "rec"),
    ADD(Integer.MIN_VALUE, "add"),
    EXD(Integer.MIN_VALUE, "exd"),
    HIT(Integer.MIN_VALUE, "hit"),
    EVA(Integer.MIN_VALUE, "eva"),
    POWER(0, "power"),
    WISDOM(0, "wisdom"),
    AGILITY(0, "agility"),
    MOVE_SPEED(0, "moveSpeed"),
    ATTACK_SPEED(0, "attackSpeed"),
    PHY_RES(0, "phyRes"),
    PUN_RES(0, "punRes"),
    MAG_RES(0, "magRes")
    ;

    int code;

    String msg;

    String remark;

    int min;

    private static final long serialVersionUID = 1L;

    E_Attribute(int min, String msg)
    {
        this.min = min;
        this.msg = msg;
    }

    public void init(AttributeConfig attributeConfig)
    {
        this.code = attributeConfig.id;
//        this.msg = attributeConfig.name;
        this.remark = attributeConfig.remark;
    }

    public static E_Attribute forNumber(int id)
    {
        for(E_Attribute attribute : values())
        {
            if(attribute.code == id)
                return attribute;
        }
        return null;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public int getMin()
    {
        return min;
    }


    public static boolean checkInit(AttributeConfig attributeConfig)
    {
        for(E_Attribute attribute : values())
        {
            if(attribute.getMsg().equals(attributeConfig.getName()))
            {
                attribute.init(attributeConfig);
                return true;
            }
        }
        return false;
    }


    @Override
    public String toString() {
        return "E_Attribute{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", remark='" + remark + '\'' +
                "} " ;
    }
}
